package com.wzw.springboot.principle.expansion.event;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * @author Wangzhiwen
 */
@Component
public class EventPublishHandler implements ApplicationEventPublisherAware {

    // AnnotationConfigServletWebServerApplicationContext
    private static ApplicationEventPublisher eventPublisher;

    @Override
    @SuppressWarnings("all")
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        EventPublishHandler.eventPublisher = applicationEventPublisher;
    }

    public static void publishEvent(PrincipleEvent principleEvent) {
        Assert.notNull(eventPublisher, "ApplicationEventPublisher Is Null");
        eventPublisher.publishEvent(principleEvent);
    }
}
